package com.ruoyi.web.controller.system;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.SysTreeDictType;
import com.ruoyi.system.service.ISysTreeDictTypeService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 树形字典类型Controller
 * 
 * @author genghz
 * @date 2021-11-17
 */
@RestController
@RequestMapping("/system/tree")
public class SysTreeDictTypeController extends BaseController
{
    @Autowired
    private ISysTreeDictTypeService sysTreeDictTypeService;

    /**
     * 查询树形字典类型列表
     */
    @PreAuthorize("@ss.hasPermi('system:tree:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysTreeDictType sysTreeDictType)
    {
        startPage();
        List<SysTreeDictType> list = sysTreeDictTypeService.selectSysTreeDictTypeList(sysTreeDictType);
        return getDataTable(list);
    }

    /**
     * 导出树形字典类型列表
     */
    @PreAuthorize("@ss.hasPermi('system:tree:export')")
    @Log(title = "树形字典类型", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(SysTreeDictType sysTreeDictType)
    {
        List<SysTreeDictType> list = sysTreeDictTypeService.selectSysTreeDictTypeList(sysTreeDictType);
        ExcelUtil<SysTreeDictType> util = new ExcelUtil<SysTreeDictType>(SysTreeDictType.class);
        return util.exportExcel(list, "树形字典类型数据");
    }

    /**
     * 获取树形字典类型详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:tree:query')")
    @GetMapping(value = "/{dictId}")
    public AjaxResult getInfo(@PathVariable("dictId") Long dictId)
    {
        return AjaxResult.success(sysTreeDictTypeService.selectSysTreeDictTypeByDictId(dictId));
    }

    /**
     * 新增树形字典类型
     */
    @PreAuthorize("@ss.hasPermi('system:tree:add')")
    @Log(title = "树形字典类型", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysTreeDictType sysTreeDictType)
    {
        return toAjax(sysTreeDictTypeService.insertSysTreeDictType(sysTreeDictType));
    }

    /**
     * 修改树形字典类型
     */
    @PreAuthorize("@ss.hasPermi('system:tree:edit')")
    @Log(title = "树形字典类型", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysTreeDictType sysTreeDictType)
    {
        return toAjax(sysTreeDictTypeService.updateSysTreeDictType(sysTreeDictType));
    }

    /**
     * 删除树形字典类型
     */
    @PreAuthorize("@ss.hasPermi('system:tree:remove')")
    @Log(title = "树形字典类型", businessType = BusinessType.DELETE)
	@DeleteMapping("/{dictIds}")
    public AjaxResult remove(@PathVariable Long[] dictIds)
    {
        return toAjax(sysTreeDictTypeService.deleteSysTreeDictTypeByDictIds(dictIds));
    }
}
